package com.trust.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.trust.agri.response.ResponseResult;
import com.trust.agri.sign.validate.SaveValidate;
import com.trust.annotation.SYQLog;
import com.trust.entity.DTO.FieldDTO;
import com.trust.entity.Field;
import com.trust.entity.Param.FieldListParam;
import com.trust.entity.VO.FieldListVO;
import com.trust.service.FieldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/api/field")
@Api(value = "农事作业 - 田间活动", tags = "农事作业 - 田间活动")
public class FieldController {

    @Resource
    private FieldService service;

    @PostMapping("/list")
    @ApiOperation("田间活动列表")
    public ResponseResult<Page<FieldListVO>> list(@RequestBody FieldListParam param){
        Page<FieldListVO> vo = service.list(param);
        return ResponseResult.ok(vo);
    }

    @PostMapping("/save")
    @ApiOperation("新增田间活动")
    @SYQLog(type = "新增田间活动", name = "田间活动")
    public ResponseResult<Field> save(@Validated(SaveValidate.class) @RequestBody FieldDTO param){
        Field field = service.saveAndUpdate(param);
        return ResponseResult.ok(field);
    }
}
